<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="管理单位" prop="managementUnit">
        <el-input
          v-model="queryParams.managementUnit"
          placeholder="请输入管理单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称" prop="designation">
        <el-input
          v-model="queryParams.designation"
          placeholder="请输入名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="有效期">
        <el-date-picker
          v-model="daterangeNextVerification"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          unlink-panels
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['meter:ledger:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['meter:ledger:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['meter:ledger:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['meter:ledger:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ledgerList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="无意义主键" align="center" prop="projectId"/>
      <el-table-column label="管理单位" align="center" prop="managementUnit"/>
      <el-table-column label="所在区域" align="center" prop="area"/>
      <el-table-column label="工序" align="center" prop="process"/>
      <el-table-column label="安装位置" align="center" prop="position"/>
      <el-table-column label="介质" align="center" prop="storageMedium"/>
      <el-table-column label="名称" align="center" prop="designation"/>
      <el-table-column label="设备类型" align="center" prop="deviceType"/>
      <el-table-column label="作用" align="center" prop="effect"/>
      <el-table-column label="品牌" align="center" prop="brand"/>
      <el-table-column label="规格型号" align="center" prop="modelNumber"/>
      <el-table-column label="管径/供电方式" align="center" prop="powersupplymode"/>
      <el-table-column label="测量范围" align="center" prop="measurementRange"/>
      <el-table-column label="误差" align="center" prop="errorMargin"/>
      <el-table-column label="仪表等级" align="center" prop="instrumentlv"/>
      <el-table-column label="管理类别" align="center" prop="managementClass"/>
      <el-table-column label="属性" align="center" prop="stats"/>
      <el-table-column label="数据采集" align="center" prop="dataAcquisition"/>
      <el-table-column label="采集方式" align="center" prop="acquisitionmode"/>
      <el-table-column label="检定周期" align="center" prop="verificationCycle"/>
      <el-table-column label="末次检定日期" align="center" prop="lastVerification" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastVerification, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="有效期" align="center" prop="expirationDate"/>
      <el-table-column label="次检定日期" align="center" prop="nextVerification"/>
      <el-table-column label="溯源单位" align="center" prop="traceableUnit"/>
      <el-table-column label="溯源方式" align="center" prop="traceableMode"/>
      <el-table-column label="证书编号" align="center" prop="certificateNumber"/>
      <el-table-column label="证书结论" align="center" prop="certificateConclusion"/>
      <el-table-column label="确认结论" align="center" prop="conclusion"/>
      <el-table-column label="状态" align="center" prop="confirmationState"/>
      <el-table-column label="测量过程编号" align="center" prop="processNumber"/>
      <el-table-column label="校准计量" align="center" prop="calibrationRecord"/>
      <el-table-column label="说明书" align="center" prop="specification"/>
      <el-table-column label="加入人员" align="center" prop="creator"/>
      <el-table-column label="加入时间" align="center" prop="creationtime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.creationtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="完善人员" align="center" prop="perfect"/>
      <el-table-column label="完善时间" align="center" prop="perfecttime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.perfecttime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="删除人员" align="center" prop="deleteor"/>
      <el-table-column label="删除时间" align="center" prop="deletetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deletetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark"/>
      <!--      <el-table-column label="预留字段" align="center" prop="free1" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free2" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free3" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free4" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free5" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free6" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free7" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free8" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free9" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free11" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free12" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free13" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free14" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free15" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free16" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free17" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free18" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free19" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free20" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free21" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free22" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free23" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free24" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free25" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free26" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free27" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free28" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free29" />-->
      <!--      <el-table-column label="预留字段" align="center" prop="free30" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['meter:ledger:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['meter:ledger:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport"/>
            是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
                   @click="importTemplate"
          >下载模板
          </el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改计量台账对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="管理单位" prop="managementUnit">
          <el-input v-model="form.managementUnit" placeholder="请输入管理单位"/>
        </el-form-item>
        <el-form-item label="所在区域" prop="area">
          <el-input v-model="form.area" placeholder="请输入所在区域"/>
        </el-form-item>
        <el-form-item label="工序" prop="process">
          <el-input v-model="form.process" placeholder="请输入工序"/>
        </el-form-item>
        <el-form-item label="安装位置" prop="position">
          <el-input v-model="form.position" placeholder="请输入安装位置"/>
        </el-form-item>
        <el-form-item label="介质" prop="storageMedium">
          <el-input v-model="form.storageMedium" placeholder="请输入介质"/>
        </el-form-item>
        <el-form-item label="名称" prop="designation">
          <el-input v-model="form.designation" placeholder="请输入名称"/>
        </el-form-item>
        <el-form-item label="作用" prop="effect">
          <el-input v-model="form.effect" placeholder="请输入作用"/>
        </el-form-item>
        <el-form-item label="品牌" prop="brand">
          <el-input v-model="form.brand" placeholder="请输入品牌"/>
        </el-form-item>
        <el-form-item label="规格型号" prop="modelNumber">
          <el-input v-model="form.modelNumber" placeholder="请输入规格型号"/>
        </el-form-item>
        <el-form-item label="管径/供电方式" prop="powersupplymode">
          <el-input v-model="form.powersupplymode" placeholder="请输入管径/供电方式"/>
        </el-form-item>
        <el-form-item label="测量范围" prop="measurementRange">
          <el-input v-model="form.measurementRange" placeholder="请输入测量范围"/>
        </el-form-item>
        <el-form-item label="误差" prop="errorMargin">
          <el-input v-model="form.errorMargin" placeholder="请输入误差"/>
        </el-form-item>
        <el-form-item label="仪表等级" prop="instrumentlv">
          <el-input v-model="form.instrumentlv" placeholder="请输入仪表等级"/>
        </el-form-item>
        <el-form-item label="管理类别" prop="managementClass">
          <el-input v-model="form.managementClass" placeholder="请输入管理类别"/>
        </el-form-item>
        <el-form-item label="属性" prop="stats">
          <el-input v-model="form.stats" placeholder="请输入属性"/>
        </el-form-item>
        <el-form-item label="数据采集" prop="dataAcquisition">
          <el-input v-model="form.dataAcquisition" placeholder="请输入数据采集"/>
        </el-form-item>
        <el-form-item label="采集方式" prop="acquisitionmode">
          <el-input v-model="form.acquisitionmode" placeholder="请输入采集方式"/>
        </el-form-item>
        <el-form-item label="检定周期" prop="verificationCycle">
          <el-input v-model="form.verificationCycle" placeholder="请输入检定周期"/>
        </el-form-item>
        <el-form-item label="末次检定日期" prop="lastVerification">
          <el-date-picker clearable size="small"
                          v-model="form.lastVerification"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择末次检定日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="有效期" prop="expirationDate">
          <el-input v-model="form.expirationDate" placeholder="请输入有效期"/>
        </el-form-item>
        <el-form-item label="次检定日期" prop="nextVerification">
          <el-input v-model="form.nextVerification" placeholder="请输入次检定日期"/>
        </el-form-item>
        <el-form-item label="溯源单位" prop="traceableUnit">
          <el-input v-model="form.traceableUnit" placeholder="请输入溯源单位"/>
        </el-form-item>
        <el-form-item label="溯源方式" prop="traceableMode">
          <el-input v-model="form.traceableMode" placeholder="请输入溯源方式"/>
        </el-form-item>
        <el-form-item label="证书编号" prop="certificateNumber">
          <el-input v-model="form.certificateNumber" placeholder="请输入证书编号"/>
        </el-form-item>
        <el-form-item label="证书结论" prop="certificateConclusion">
          <el-input v-model="form.certificateConclusion" placeholder="请输入证书结论"/>
        </el-form-item>
        <el-form-item label="确认结论" prop="conclusion">
          <el-input v-model="form.conclusion" placeholder="请输入确认结论"/>
        </el-form-item>
        <el-form-item label="状态" prop="confirmationState">
          <el-input v-model="form.confirmationState" placeholder="请输入状态"/>
        </el-form-item>
        <el-form-item label="测量过程编号" prop="processNumber">
          <el-input v-model="form.processNumber" placeholder="请输入测量过程编号"/>
        </el-form-item>
        <el-form-item label="校准计量" prop="calibrationRecord">
          <el-input v-model="form.calibrationRecord" placeholder="请输入校准计量"/>
        </el-form-item>
        <el-form-item label="说明书">
          <imageUpload v-model="form.specification"/>
        </el-form-item>
        <el-form-item label="加入人员" prop="creator">
          <el-input v-model="form.creator" placeholder="请输入加入人员"/>
        </el-form-item>
        <el-form-item label="加入时间" prop="creationtime">
          <el-date-picker clearable size="small"
                          v-model="form.creationtime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择加入时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="完善人员" prop="perfect">
          <el-input v-model="form.perfect" placeholder="请输入完善人员"/>
        </el-form-item>
        <el-form-item label="完善时间" prop="perfecttime">
          <el-date-picker clearable size="small"
                          v-model="form.perfecttime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择完善时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除人员" prop="deleteor">
          <el-input v-model="form.deleteor" placeholder="请输入删除人员"/>
        </el-form-item>
        <el-form-item label="删除时间" prop="deletetime">
          <el-date-picker clearable size="small"
                          v-model="form.deletetime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择删除时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注"/>
        </el-form-item>
        <!--        <el-form-item label="预留字段" prop="free1">-->
        <!--          <el-input v-model="form.free1" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free2">-->
        <!--          <el-input v-model="form.free2" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free3">-->
        <!--          <el-input v-model="form.free3" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free4">-->
        <!--          <el-input v-model="form.free4" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free5">-->
        <!--          <el-input v-model="form.free5" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free6">-->
        <!--          <el-input v-model="form.free6" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free7">-->
        <!--          <el-input v-model="form.free7" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free8">-->
        <!--          <el-input v-model="form.free8" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free9">-->
        <!--          <el-input v-model="form.free9" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free11">-->
        <!--          <el-input v-model="form.free11" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free12">-->
        <!--          <el-input v-model="form.free12" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free13">-->
        <!--          <el-input v-model="form.free13" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free14">-->
        <!--          <el-input v-model="form.free14" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free15">-->
        <!--          <el-input v-model="form.free15" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free16">-->
        <!--          <el-input v-model="form.free16" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free17">-->
        <!--          <el-input v-model="form.free17" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free18">-->
        <!--          <el-input v-model="form.free18" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free19">-->
        <!--          <el-input v-model="form.free19" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free20">-->
        <!--          <el-input v-model="form.free20" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free21">-->
        <!--          <el-input v-model="form.free21" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free22">-->
        <!--          <el-input v-model="form.free22" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free23">-->
        <!--          <el-input v-model="form.free23" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free24">-->
        <!--          <el-input v-model="form.free24" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free25">-->
        <!--          <el-input v-model="form.free25" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free26">-->
        <!--          <el-input v-model="form.free26" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free27">-->
        <!--          <el-input v-model="form.free27" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free28">-->
        <!--          <el-input v-model="form.free28" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free29">-->
        <!--          <el-input v-model="form.free29" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="预留字段" prop="free30">-->
        <!--          <el-input v-model="form.free30" placeholder="请输入预留字段" />-->
        <!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listLedger, getLedger, delLedger, addLedger, updateLedger } from '@/api/meter/ledger'

export default {
  name: 'Ledger',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 计量台账表格数据
      ledgerList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        managementUnit: null,
        designation: null,
        deviceType: null,
        verificationCycle: null,
        lastVerification: null,
        expirationDate: null,
        nextVerification: null,
        traceableUnit: null,
        traceableMode: null,
        certificateNumber: null,
        certificateConclusion: null,
        conclusion: null,
        confirmationState: null,
        processNumber: null,
        calibrationRecord: null,
        specification: null,
        creator: null,
        creationtime: null,
        perfect: null,
        perfecttime: null,
        deleteor: null,
        deletetime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
// 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: 'Bearer ' + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + '/meter/ledger/importData'
      }
    };
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询计量台账列表 */
    getList() {
      this.loading = true
      listLedger(this.queryParams).then(response => {
        this.ledgerList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        projectId: null,
        managementUnit: null,
        area: null,
        process: null,
        position: null,
        storageMedium: null,
        designation: null,
        deviceType: null,
        effect: null,
        brand: null,
        modelNumber: null,
        powersupplymode: null,
        measurementRange: null,
        errorMargin: null,
        instrumentlv: null,
        managementClass: null,
        stats: null,
        dataAcquisition: null,
        acquisitionmode: null,
        verificationCycle: null,
        lastVerification: null,
        expirationDate: null,
        nextVerification: null,
        traceableUnit: null,
        traceableMode: null,
        certificateNumber: null,
        certificateConclusion: null,
        conclusion: null,
        confirmationState: null,
        processNumber: null,
        calibrationRecord: null,
        specification: null,
        creator: null,
        creationtime: null,
        perfect: null,
        perfecttime: null,
        deleteor: null,
        deletetime: null,
        remark: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        free1: null,
        free2: null,
        free3: null,
        free4: null,
        free5: null,
        free6: null,
        free7: null,
        free8: null,
        free9: null,
        free11: null,
        free12: null,
        free13: null,
        free14: null,
        free15: null,
        free16: null,
        free17: null,
        free18: null,
        free19: null,
        free20: null,
        free21: null,
        free22: null,
        free23: null,
        free24: null,
        free25: null,
        free26: null,
        free27: null,
        free28: null,
        free29: null,
        free30: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.projectId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加计量台账'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const projectId = row.projectId || this.ids
      getLedger(projectId).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改计量台账'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.projectId != null) {
            updateLedger(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addLedger(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const projectIds = row.projectId || this.ids
      this.$modal.confirm('是否确认删除计量台账编号为"' + projectIds + '"的数据项？').then(function() {
        return delLedger(projectIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('meter/ledger/export', {
        ...this.queryParams
      }, `ledger_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false
      this.upload.isUploading = false
      this.$refs.upload.clearFiles()
      this.$alert('<div style=\'overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;\'>' + response.msg + '</div>', '导入结果', { dangerouslyUseHTMLString: true })
      this.getList()
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit()
    }

  }
}
</script>
